<?php
namespace Plu\qdh\Models\App;

use Phalcon\Mvc\Model;

class Auth extends Model
{
    // CREATE TABLE `auth` (
    //     `id` int(11) NOT NULL,
    //     `user_name` varchar(45) NOT NULL,
    //     `password` varchar(45) NOT NULL,
    //     `phone` varchar(45) NOT NULL,
    //     `create_time` int(11) DEFAULT NULL,
    //     `login_time` int(11) DEFAULT NULL,
    //     PRIMARY KEY (`id`)
    //   ) ENGINE=InnoDB DEFAULT CHARSET=utf8

    public function initialize() {
        $this->setConnectionService('db.qdh');
        $this->allowEmptyStringValues([]);
    }


	public function getSource() {
		return "auth";
    }


    static public function checkUserPswd($username, $pswd) {
        $conditions = "user_name = :username:";
        $where =[
            'conditions' => $conditions,
            'bind' => [
                'username' => $username
            ]
        ];
        $item = self::findFirst($where);
        if ($item && $item->password == $pswd) {
            return true;
        }
        return false;
    }




}